import request from '@/utils/request'
import { mockData } from './mock-data'

// 是否使用mock数据
const USE_MOCK = process.env.NODE_ENV === 'development'

// 获取日销售统计
export function getDailySales(date) {
  if (USE_MOCK) {
    return Promise.resolve(mockData.dailySales)
  }
  return request({
    url: '/statistics/daily-test',
    method: 'get',
    params: { date }
  })
}

// 获取周销售统计
export function getWeeklySales(startDate) {
  if (USE_MOCK) {
    return Promise.resolve(mockData.weeklySales)
  }
  return request({
    url: '/statistics/weekly-test',
    method: 'get',
    params: { start_date: startDate }
  })
}

// 获取月销售统计
export function getMonthlySales(yearMonth) {
  if (USE_MOCK) {
    return Promise.resolve(mockData.monthlySales)
  }
  return request({
    url: '/statistics/monthly-test',
    method: 'get',
    params: { year_month: yearMonth }
  })
}

// 获取热销商品排行
export function getTopProducts(period = 'month', limit = 20) {
  if (USE_MOCK) {
    return Promise.resolve(mockData.topProducts)
  }
  return request({
    url: '/statistics/top-products-test',
    method: 'get',
    params: { period, limit }
  })
}

// 获取销售曲线数据
export function getSalesCurve(period = 'month', granularity = 'day') {
  if (USE_MOCK) {
    return Promise.resolve(mockData.salesCurve)
  }
  return request({
    url: '/statistics/sales-curve-test',
    method: 'get',
    params: { period, granularity }
  })
}

// 获取综合统计数据
export function getComprehensiveStats() {
  if (USE_MOCK) {
    return Promise.resolve(mockData.comprehensiveStats)
  }
  return request({
    url: '/statistics/comprehensive-test',
    method: 'get'
  })
} 